import rxAjax from '@/assets/js/ajax.js';

//表单方案 api接口
const FormSolutionApi = {};

FormSolutionApi.baseUrl= '/api-form/form/core/formSolution';

/**
 * 根据别名查询表单方案
 * @param alias
 * @param id
 * @param params
 * @param action
 * @returns {*}
 */
FormSolutionApi.getByAlias =function(alias,id,params,action,appId) {
  let url= FormSolutionApi.baseUrl + "/" + alias + '/getByAlias'  ;
  let args=[];
  if(id){
      args.push("pk=" + id);
  }
  if(action){
      args.push("action=" + action);
  }
    if(appId){
        args.push("appId=" + appId);
    }
  if(args.length>0){
      url+="?" + args.join("&");
  }
  return rxAjax.postJson(url,params);
}

/**
 * 保存表单数据。
 * {setting: {action: action, alias: self.formSolutionAlias}, data: data};
 * @param parameter
 * @returns {AxiosPromise|*}
 */
FormSolutionApi.saveForm = function (parameter,appId) {
  let url = FormSolutionApi.baseUrl + '/saveForm';
    if(appId){
        url+='?appId='+appId
    }
  return rxAjax.postJson(url, parameter);
}

/**
 * 验证按钮
 * @param preCondConfig
 * @param formJson
 * @returns {*}
 */
FormSolutionApi.validPreByButton=function(preCondConfig,formJson){
    let url = FormSolutionApi.baseUrl + '/validPreByButton';
    return rxAjax.postJson(url,{config:preCondConfig,formJson:formJson});
}


/**
 * 根据配置返回数据。
 * @param params
 * @returns {*}
 */
FormSolutionApi.getValueByCustomFormConfig=function(params){
    let url = FormSolutionApi.baseUrl + '/getValueByCustomFormConfig';
    return rxAjax.postJson(url,params);
}

/**
 * 获取满足条件的流程定义ID
 */
FormSolutionApi.getFlowDefId=function(params){
  var url = FormSolutionApi.baseUrl + "/getFlowDefId";
  return rxAjax.postJson(url,params);
}

/**
 * 根据别名获取树型表单
 * @param alias
 * @param id
 * @returns {*}
 */
FormSolutionApi.getTreeByAlias=function(alias,id){
    var url=FormSolutionApi.baseUrl + '/getTreeByAlias?alias=' + alias;
    if(id){
        url += "&pk=" + id;
    }
    return rxAjax.get(url);
}

FormSolutionApi.removeById = function (parameter) {
    var url = FormSolutionApi.baseUrl + '/removeById';
    return rxAjax.postJson(url, parameter);
}

FormSolutionApi.getButtonsByFormJson=function(formSolutionAlias,formJson,appId){
  var url = FormSolutionApi.baseUrl + '/getButtonsByFormJson?formSolutionAlias='+formSolutionAlias;
  if(appId){
      url+='&appId='+appId
  }
  return rxAjax.postJson(url,formJson);
}

FormSolutionApi.getFormSolutionByAlias=function(formSolutionAlias,appId){
  var url = FormSolutionApi.baseUrl + '/getFormSolutionByAlias?alias='+formSolutionAlias;
    if(appId){
        url+='&appId='+appId
    }
  return rxAjax.get(url);
}

// 获取流程实例明细信息
FormSolutionApi.getInstDetail = function(instId){
    let url= '/api-bpm/bpm/core/bpmInst/getInstDetail?instId=' + instId;
    return rxAjax.get(url);
}

export  default FormSolutionApi;

